package com.mmall.util;

import java.math.BigDecimal;

/**
 * Created by root on 18-4-15.
 */
public class BigDecimalUtil {

    private BigDecimalUtil(){};

    public static BigDecimal add (float v1, float v2) {
        BigDecimal vb1 = new BigDecimal(Float.toString(v1));
        BigDecimal vb2 = new BigDecimal(Float.toString(v2));
        return vb1.add(vb2);
    }

    public static BigDecimal subtract (float v1, float v2) {
        BigDecimal vb1 = new BigDecimal(Float.toString(v1));
        BigDecimal vb2 = new BigDecimal(Float.toString(v2));
        return vb1.subtract(vb2);
    }

    public static BigDecimal divide (float dividend, float divisor) {
        BigDecimal dividendB = new BigDecimal(Float.toString(dividend));
        BigDecimal divisorB = new BigDecimal(Float.toString(divisor));
        return dividendB.divide(divisorB, 2, BigDecimal.ROUND_HALF_UP);
    }

    public static BigDecimal multiply (float v1, float v2) {
        BigDecimal vb1 = new BigDecimal(Float.toString(v1));
        BigDecimal vb2 = new BigDecimal(Float.toString(v2));
        return vb1.multiply(vb2);
    }
}
